import { defineStore } from "pinia"
import { getPageListData } from "@/service/globe/index"
import { DEFAULT_PRIMARY } from "@/config/index"
// import { getDarkColor } from "@/utils/tools"

const useGlobeStore = defineStore("global", {
	state: () => ({
		entireRole: [] as any,
		entireDepartment: [] as any,
		entireMenu: [] as any,

		language: "",
		themeConfig: {
			// 布局切换 ==>  纵向：vertical | 经典：classic | 横向：transverse | 分栏：columns
			layout: "vertical",
			// 默认 primary 主题颜色
			primary: DEFAULT_PRIMARY,
			// 黑夜模式
			isDark: false,
			// 折叠菜单
			isCollapse: false,
			// 面包屑导航
			breadcrumb: true,
			// 面包屑导航图标
			breadcrumbIcon: true,
			// 标签页
			tabs: true,
			// 标签页图标
			tabsIcon: true,
			// 页脚
			footer: true,
			// 当前页面是否全屏
			maximize: false
		}
	}),
	getters: {
		getMenuList: state => state.entireMenu,
		getRole: state => state.entireRole,
		getDepartment: state => state.entireDepartment
	},
	actions: {
		async getPageListDepartmentAction() {
			const { data: departmentResult } = await getPageListData("/department/list", {
				offset: 0,
				size: 10
			})
			this.entireDepartment = departmentResult.list
		},
		async getPageListRoleAction() {
			const { data: roleResult } = await getPageListData("/role/list", {
				offset: 0,
				size: 1000
			})
			this.entireRole = roleResult.list
		},
		async getPageListMenuAction() {
			const { data: menuResult } = await getPageListData("/menu/list", {})
			this.entireMenu = menuResult.list
		},
		setLanguageAction(payload: string) {
			this.language = payload
		},
		setThemeConfigAction(payload: any) {
			this.themeConfig = payload
		}
	},
	persist: {
		key: "global",
		storage: sessionStorage,
		paths: ["language", "themeConfig"]
	}
})

export default useGlobeStore
